package com.fancy.learncenter.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.VitaDetailDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.fancy.learncenter.utils.SPUtils;
import com.fancy.learncenter.utils.ToastUtil;
import com.fancy.learncenter.view.PopupWindowCity;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WorkLocationActivity extends BaseActivity {

    @Bind(R.id.salary_tv)
    EditText salaryTv;
    @Bind(R.id.work_tv)
    EditText workTv;
    @Bind(R.id.location_tv)
    TextView locationTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_location, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);
        initToolbar("求职意向");
        resumeId = getIntent().getStringExtra("resumeId");
        popupWindowCity = new PopupWindowCity(this);
        popupWindowCity.setSelectCallBack(new PopupWindowCity.SelectCallBack() {
            @Override
            public void selectCallBack(String province, String city, String area, String locationId) {
                locationTv.setText(province + city + area);
                locId = locationId;
            }

        });

        getData();
    }

    String locId;
    PopupWindowCity popupWindowCity;

    @OnClick({R.id.location_ll, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.location_ll:
                popupWindowCity.ShowPickerView();
                break;
            case R.id.submit:
                editPersonVita();
                break;
        }
    }

    String resumeId;

    private void editPersonVita() {
        Map map = new HashMap();
        if (TextUtils.isEmpty(workTv.getText().toString())) {
            ToastUtil.show("请填写期望职位");
            return;
        }

        if (TextUtils.isEmpty(salaryTv.getText().toString())) {
            ToastUtil.show("请填写期望薪资");
            return;
        }

        if (TextUtils.isEmpty(locId)) {
            ToastUtil.show("请选者工作区域");
            return;
        }

        map.put("salary", salaryTv.getText().toString());
        map.put("position", workTv.getText().toString());
        map.put("resumeId", resumeId);
        map.put("locationId", locId);

        HttpMehtod.getInstance().doIntension(map, new IdeaObserver<BaseDataBean>() {

            @Override
            public void onSuccess(BaseDataBean listBaseDataBean) {
                ToastUtil.show("资料已更新");
                finish();
            }

            @Override
            public void onFail(int errorCode) {

            }
        });

    }


    public void getData() {
        Map map = new HashMap();
        map.put("token", SPUtils.getToken());
        map.put("userId", SPUtils.getUserID());
        HttpMehtod.getInstance().getVita(map, new IdeaObserver<BaseDataBean<VitaDetailDataBean>>() {

            @Override
            public void onSuccess(BaseDataBean<VitaDetailDataBean> vitaDetailDataBeanBaseDataBean) {


                if (vitaDetailDataBeanBaseDataBean.getData().getLocation() != null) {
                    locationTv.setText(vitaDetailDataBeanBaseDataBean.getData().getLocation().getAreaname());
                }

                if (vitaDetailDataBeanBaseDataBean.getData().getPosition() != null) {
                    workTv.setText(vitaDetailDataBeanBaseDataBean.getData().getPosition());
                }

                if (vitaDetailDataBeanBaseDataBean.getData().getSalary() != null) {
                    salaryTv.setText(vitaDetailDataBeanBaseDataBean.getData().getSalary());
                }


            }

            @Override
            public void onFail(int errorCode) {

            }

        });
    }
}
